package com.eascs.p2p.admin.service.impl;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.p2p.admin.manager.IDatadicManager;
import com.eascs.p2p.common.entity.DatadicEntity;
import com.eascs.p2p.common.entity.DatadicItemEntity;
import com.eascs.p2p.common.service.IDatadicService;
import com.eascs.p2p.common.vo.DatadicVO;
import com.eascs.p2p.common.vo.ModelResult;

@Service
public class DatadicServiceImpl implements IDatadicService {
	@Inject
	IDatadicManager datadicManager;

	@Override
	public ModelResult<PageResult<Object[]>> pageFindDatadic(DatadicVO vo) {
		
		ModelResult<PageResult<Object[]>> result = new ModelResult<PageResult<Object[]>>();
		try {
			result.setModel(datadicManager.pageFindDatadic(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("分页查询字典表信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<PageResult<Object[]>> queryDatadicItemByID(DatadicVO vo) {
		ModelResult<PageResult<Object[]>> result = new ModelResult<PageResult<Object[]>>();
		try {
			result.setModel(datadicManager.queryDatadicItemByID(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据字典表id查询字典表详情信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<String> addDatadic(DatadicEntity entity) {
		ModelResult<String> result = new ModelResult<String>();
		try {
			result.setModel(datadicManager.addDatadic(entity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("添加字典表信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> updateDatadic(DatadicEntity entity) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(datadicManager.updateDatadic(entity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("修改字典表信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> deleteDatadic(String id) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(datadicManager.deleteDatadic(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("删除字典表信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<String> addDatadicItem(DatadicItemEntity entity) {
		ModelResult<String> result = new ModelResult<String>();
		try {
			result.setModel(datadicManager.addDatadicItem(entity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("添加字典表详情信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> updateDatadicItem(DatadicItemEntity entity) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(datadicManager.updateDatadicItem(entity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("修改字典表详情信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> deleteDatadicItem(String id) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(datadicManager.deleteDatadicItem(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("删除字典表详情信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<DatadicEntity> findDatadicByID(String id) {
		ModelResult<DatadicEntity> result = new ModelResult<DatadicEntity>();
		try {
			result.setModel(datadicManager.findDatadicByID(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据id查询字典表信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<DatadicItemEntity> findDatadicItemByID(String id) {
		ModelResult<DatadicItemEntity> result = new ModelResult<DatadicItemEntity>();
		try {
			result.setModel(datadicManager.findDatadicItemByID(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据i字典详情表id查询字典表详情信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Integer> isExistDatadic(String ddCode) {
	
		ModelResult<Integer> result = new ModelResult<Integer>();
		try {
			result.setModel(datadicManager.isExistDatadic(ddCode));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据字典code，查询是否已经存在相同code字典信息：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Integer> isExistDatadicItem(String ddNo, String itemCode) {
		ModelResult<Integer> result = new ModelResult<Integer>();
		try {
			result.setModel(datadicManager.isExistDatadicItem(ddNo,itemCode));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据字典id、字典详情code，查询是否已经存在相同code字典详情信息：", e.getMessage());
		}
		return result;
	}


}
